import React, { Component } from 'react';
import {Link,Route,Redirect,Switch} from 'react-router-dom';
import Home from './views/Home';
import List from './views/List';
import Todo from './views/Todo';
import Detail from './views/Detail';

class App extends Component {
  render() {
    let login = true;
    return (
      <div className="App">
        <h2>react-router</h2>
        <hr />
        <Link to="/">首页</Link>
        <span> | </span>
        <Link to="/list">列表</Link>
        <span> | </span>
        <Link to="/todoList">TodoList</Link>
        {/*<Redirect to="/todoList"></Redirect>*/}

        {/*<Route path="/" exact={true} component={Home}></Route>*/}
        {/*<Route path="/" exact={true} render={()=>(<Home />)}></Route>*/}
        <Switch>
          <Route path="/list" component={List}></Route>
          <Route path="/todoList" component={Todo}></Route>
          <Route path="/detail/:id" component={Detail}></Route>
          <Route path="/" render={()=>{
            if( login ){
              return <Home />
            }else{
              return <Redirect to="/todoList" />
            }
          }}></Route>
        </Switch>

      </div>
    );
  }
}

export default App;
